package com.yale.cxfsoapws.config;

import com.yale.cxfsoapws.service.DifferentNameSpaceService;
import com.yale.cxfsoapws.service.UserService;
import com.yale.cxfsoapws.service.impl.DifferentNameSpaceServiceImpl;
import com.yale.cxfsoapws.service.impl.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @author yale
 * @date 2017/8/16
 * @version 2.0
 *
 * Spring boot 整合 cxf
 *
 */
@Configuration
public class CxfConfig {

    @Bean
    public ServletRegistrationBean dispatcherServlet(){
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return  new SpringBus();
    }

    @Bean
    public UserService userService(){
        return new UserServiceImpl();
    }
    @Bean
    public DifferentNameSpaceService diffService(){
        return new DifferentNameSpaceServiceImpl();
    }

    @Bean
    public Endpoint endpoint(){
        //org.apache.cxf.jaxws.EndpointImpl;
        EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
//        endpoint = new EndpointImpl(springBus(), diffService());
//        endpoint.publish("/user");
        String address = "/user";
        endpoint.publish(address, userService());

        String address1 = "/diff";
        endpoint.publish(address1, diffService());
        return endpoint;
    }

}
